package dao;
import entity.Typeb;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import static org.hibernate.criterion.Example.create;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TypebDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(TypebDAO.class);

	public void save(Typeb transientInstance) {
		log.debug("saving Typeb instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Typeb persistentInstance) {
		log.debug("deleting Typeb instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Typeb findById(java.lang.Integer id) {
		log.debug("getting Typeb instance with id: " + id);
		try {
			Typeb instance = (Typeb) getSession().get("entity.Typeb", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
  public List findByTypeAndFes(int idev,int idType) {
        log.debug("finding all TypeBillet instances");
        try {
            String queryString = "from Typeb where id_event="+idev+"  and id_type ="+idType+" order by id";
            Query queryObject = getSession().createQuery(queryString);
            return queryObject.list();
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }
  
	public List<Typeb> findByExample(Typeb instance) {
		log.debug("finding Typeb instance by example");
		try {
			List<Typeb> results = (List<Typeb>) getSession()
					.createCriteria("entity.Typeb").add(create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Typeb instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Typeb as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findAll() {
		log.debug("finding all Typeb instances");
		try {
			String queryString = "from Typeb";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
        
        public List findByTypeWeb() {
		log.debug("finding all Typeb instances");
		try {
			String queryString = "from Typeb";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.setMaxResults(62).list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
        
        
        public List findByEventChaise(int id) {
		log.debug("finding all Typeb instances");
		try {
			String queryString = "from Typeb where id_event="+id +" and id_type=1";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

         public List findByEventGradin(int id) {
		log.debug("finding all Typeb instances");
		try {
			String queryString = "from Typeb where id_event="+id +" and id_type=2";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	public Typeb merge(Typeb detachedInstance) {
		log.debug("merging Typeb instance");
		try {
			Typeb result = (Typeb) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Typeb instance) {
		log.debug("attaching dirty Typeb instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Typeb instance) {
		log.debug("attaching clean Typeb instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

    
}